<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>数据库 | 自由·生活</title>
    <meta name="generator" content="VuePress 1.5.4">
    <link rel="icon" href="images/favicon.ico">
    <script language="javascript" type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/MouseClickEffect.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css">
    <meta name="description" content="脱离生存而生活，寻求自由">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <link rel="preload" href="/assets/css/0.styles.8c3033ea.css" as="style"><link rel="preload" href="/assets/js/app.0e76bb72.js" as="script"><link rel="preload" href="/assets/js/3.c5829877.js" as="script"><link rel="preload" href="/assets/js/1.695f3f80.js" as="script"><link rel="preload" href="/assets/js/238.8c792409.js" as="script"><link rel="prefetch" href="/assets/js/10.fdc11bc7.js"><link rel="prefetch" href="/assets/js/100.3e29fa54.js"><link rel="prefetch" href="/assets/js/101.19f861f4.js"><link rel="prefetch" href="/assets/js/102.0eb344c2.js"><link rel="prefetch" href="/assets/js/103.167b5aab.js"><link rel="prefetch" href="/assets/js/104.3463b648.js"><link rel="prefetch" href="/assets/js/105.fc782f3d.js"><link rel="prefetch" href="/assets/js/106.b2d60f6a.js"><link rel="prefetch" href="/assets/js/107.91f5548b.js"><link rel="prefetch" href="/assets/js/108.8bcbfcd7.js"><link rel="prefetch" href="/assets/js/109.a0dd87a3.js"><link rel="prefetch" href="/assets/js/11.5d72653a.js"><link rel="prefetch" href="/assets/js/110.8d3b5064.js"><link rel="prefetch" href="/assets/js/111.6e109181.js"><link rel="prefetch" href="/assets/js/112.7130a6e7.js"><link rel="prefetch" href="/assets/js/113.6c962a0e.js"><link rel="prefetch" href="/assets/js/114.82175aae.js"><link rel="prefetch" href="/assets/js/115.a83e6a2d.js"><link rel="prefetch" href="/assets/js/116.70ebc8b4.js"><link rel="prefetch" href="/assets/js/117.368509d0.js"><link rel="prefetch" href="/assets/js/118.54fdc470.js"><link rel="prefetch" href="/assets/js/119.64d2a2a3.js"><link rel="prefetch" href="/assets/js/12.bfde6b78.js"><link rel="prefetch" href="/assets/js/120.5b47488f.js"><link rel="prefetch" href="/assets/js/121.82865d4b.js"><link rel="prefetch" href="/assets/js/122.619e60ca.js"><link rel="prefetch" href="/assets/js/123.66c3fb26.js"><link rel="prefetch" href="/assets/js/124.4381768b.js"><link rel="prefetch" href="/assets/js/125.2f39619b.js"><link rel="prefetch" href="/assets/js/126.0c622bc6.js"><link rel="prefetch" href="/assets/js/127.caee15ee.js"><link rel="prefetch" href="/assets/js/128.99714900.js"><link rel="prefetch" href="/assets/js/129.ff59083b.js"><link rel="prefetch" href="/assets/js/13.2b3528b1.js"><link rel="prefetch" href="/assets/js/130.76df0e89.js"><link rel="prefetch" href="/assets/js/131.2333a328.js"><link rel="prefetch" href="/assets/js/132.65cff4f4.js"><link rel="prefetch" href="/assets/js/133.2c0991bc.js"><link rel="prefetch" href="/assets/js/134.fe5fc3a5.js"><link rel="prefetch" href="/assets/js/135.aef0a809.js"><link rel="prefetch" href="/assets/js/136.90fd1b1d.js"><link rel="prefetch" href="/assets/js/137.07750a3f.js"><link rel="prefetch" href="/assets/js/138.723bd2c0.js"><link rel="prefetch" href="/assets/js/139.d22450b7.js"><link rel="prefetch" href="/assets/js/14.b769124c.js"><link rel="prefetch" href="/assets/js/140.1659de26.js"><link rel="prefetch" href="/assets/js/141.f713c5ec.js"><link rel="prefetch" href="/assets/js/142.63ebd83f.js"><link rel="prefetch" href="/assets/js/143.404a833f.js"><link rel="prefetch" href="/assets/js/144.3e0107ef.js"><link rel="prefetch" href="/assets/js/145.cef80531.js"><link rel="prefetch" href="/assets/js/146.c68d17d7.js"><link rel="prefetch" href="/assets/js/147.0af3acbb.js"><link rel="prefetch" href="/assets/js/148.9f0d2452.js"><link rel="prefetch" href="/assets/js/149.28785960.js"><link rel="prefetch" href="/assets/js/15.7c3421d9.js"><link rel="prefetch" href="/assets/js/150.bf310c33.js"><link rel="prefetch" href="/assets/js/151.de6313cc.js"><link rel="prefetch" href="/assets/js/152.91a567b5.js"><link rel="prefetch" href="/assets/js/153.cfe26382.js"><link rel="prefetch" href="/assets/js/154.047349d0.js"><link rel="prefetch" href="/assets/js/155.6923503c.js"><link rel="prefetch" href="/assets/js/156.2443e22f.js"><link rel="prefetch" href="/assets/js/157.fac2fc32.js"><link rel="prefetch" href="/assets/js/158.3d470963.js"><link rel="prefetch" href="/assets/js/159.9512719e.js"><link rel="prefetch" href="/assets/js/16.baa49355.js"><link rel="prefetch" href="/assets/js/160.1a610cc3.js"><link rel="prefetch" href="/assets/js/161.b240977c.js"><link rel="prefetch" href="/assets/js/162.cfb78d5a.js"><link rel="prefetch" href="/assets/js/163.3c935aea.js"><link rel="prefetch" href="/assets/js/164.0188664b.js"><link rel="prefetch" href="/assets/js/165.6f4ba8e0.js"><link rel="prefetch" href="/assets/js/166.32b92de7.js"><link rel="prefetch" href="/assets/js/167.1087cc58.js"><link rel="prefetch" href="/assets/js/168.7e81ac69.js"><link rel="prefetch" href="/assets/js/169.5270c30b.js"><link rel="prefetch" href="/assets/js/17.2270e174.js"><link rel="prefetch" href="/assets/js/170.1d6bc941.js"><link rel="prefetch" href="/assets/js/171.e3781bc6.js"><link rel="prefetch" href="/assets/js/172.54d7bc4b.js"><link rel="prefetch" href="/assets/js/173.a88f9e1f.js"><link rel="prefetch" href="/assets/js/174.7d882351.js"><link rel="prefetch" href="/assets/js/175.7a0c6feb.js"><link rel="prefetch" href="/assets/js/176.12b22e86.js"><link rel="prefetch" href="/assets/js/177.b2230eac.js"><link rel="prefetch" href="/assets/js/178.023ba5be.js"><link rel="prefetch" href="/assets/js/179.53fa03a8.js"><link rel="prefetch" href="/assets/js/18.988151ff.js"><link rel="prefetch" href="/assets/js/180.f17c3614.js"><link rel="prefetch" href="/assets/js/181.8872481a.js"><link rel="prefetch" href="/assets/js/182.c57e38bc.js"><link rel="prefetch" href="/assets/js/183.7085d12e.js"><link rel="prefetch" href="/assets/js/184.aa164e5b.js"><link rel="prefetch" href="/assets/js/185.b7ed0f6b.js"><link rel="prefetch" href="/assets/js/186.f08304c9.js"><link rel="prefetch" href="/assets/js/187.4a10e63d.js"><link rel="prefetch" href="/assets/js/188.f0463437.js"><link rel="prefetch" href="/assets/js/189.cff969e0.js"><link rel="prefetch" href="/assets/js/19.c196a261.js"><link rel="prefetch" href="/assets/js/190.adc3524b.js"><link rel="prefetch" href="/assets/js/191.a14895a8.js"><link rel="prefetch" href="/assets/js/192.e595f819.js"><link rel="prefetch" href="/assets/js/193.3cbcef2c.js"><link rel="prefetch" href="/assets/js/194.55530a96.js"><link rel="prefetch" href="/assets/js/195.1a834f79.js"><link rel="prefetch" href="/assets/js/196.001dd10b.js"><link rel="prefetch" href="/assets/js/197.4b9de142.js"><link rel="prefetch" href="/assets/js/198.955a06ea.js"><link rel="prefetch" href="/assets/js/199.9d63eea7.js"><link rel="prefetch" href="/assets/js/20.74b35545.js"><link rel="prefetch" href="/assets/js/200.8fe0777d.js"><link rel="prefetch" href="/assets/js/201.a91425c3.js"><link rel="prefetch" href="/assets/js/202.5b89464a.js"><link rel="prefetch" href="/assets/js/203.e48d18e2.js"><link rel="prefetch" href="/assets/js/204.6cbc5c79.js"><link rel="prefetch" href="/assets/js/205.d26879e9.js"><link rel="prefetch" href="/assets/js/206.fd8688f3.js"><link rel="prefetch" href="/assets/js/207.ef25eb3d.js"><link rel="prefetch" href="/assets/js/208.9f0e5ab2.js"><link rel="prefetch" href="/assets/js/209.cbd7c763.js"><link rel="prefetch" href="/assets/js/21.3cbc9110.js"><link rel="prefetch" href="/assets/js/210.6b733c20.js"><link rel="prefetch" href="/assets/js/211.2b986a0a.js"><link rel="prefetch" href="/assets/js/212.faee0dc6.js"><link rel="prefetch" href="/assets/js/213.7ed75653.js"><link rel="prefetch" href="/assets/js/214.825d2d93.js"><link rel="prefetch" href="/assets/js/215.251aa760.js"><link rel="prefetch" href="/assets/js/216.11962b03.js"><link rel="prefetch" href="/assets/js/217.62e3335a.js"><link rel="prefetch" href="/assets/js/218.a7c3b793.js"><link rel="prefetch" href="/assets/js/219.5ff63a4c.js"><link rel="prefetch" href="/assets/js/22.d2507cce.js"><link rel="prefetch" href="/assets/js/220.28ea20d6.js"><link rel="prefetch" href="/assets/js/221.6108e4e1.js"><link rel="prefetch" href="/assets/js/222.73443d85.js"><link rel="prefetch" href="/assets/js/223.e115734d.js"><link rel="prefetch" href="/assets/js/224.499e0bab.js"><link rel="prefetch" href="/assets/js/225.70887ebb.js"><link rel="prefetch" href="/assets/js/226.e683c623.js"><link rel="prefetch" href="/assets/js/227.06f8bc32.js"><link rel="prefetch" href="/assets/js/228.82faf31a.js"><link rel="prefetch" href="/assets/js/229.0f8a6911.js"><link rel="prefetch" href="/assets/js/23.8da30b89.js"><link rel="prefetch" href="/assets/js/230.f895ca67.js"><link rel="prefetch" href="/assets/js/231.34717d1d.js"><link rel="prefetch" href="/assets/js/232.c7857239.js"><link rel="prefetch" href="/assets/js/233.6b7bcffd.js"><link rel="prefetch" href="/assets/js/234.0e0da6a5.js"><link rel="prefetch" href="/assets/js/235.5bc065c0.js"><link rel="prefetch" href="/assets/js/236.3e91ceb0.js"><link rel="prefetch" href="/assets/js/237.9116740e.js"><link rel="prefetch" href="/assets/js/239.b4d8dfb8.js"><link rel="prefetch" href="/assets/js/24.3014a3d4.js"><link rel="prefetch" href="/assets/js/240.a1e61d58.js"><link rel="prefetch" href="/assets/js/241.3c016709.js"><link rel="prefetch" href="/assets/js/242.f8620e3f.js"><link rel="prefetch" href="/assets/js/243.8f53f134.js"><link rel="prefetch" href="/assets/js/244.424903c4.js"><link rel="prefetch" href="/assets/js/245.96c86aae.js"><link rel="prefetch" href="/assets/js/25.03ca3aa9.js"><link rel="prefetch" href="/assets/js/26.4916e6b8.js"><link rel="prefetch" href="/assets/js/27.f9aab712.js"><link rel="prefetch" href="/assets/js/28.1dfbff97.js"><link rel="prefetch" href="/assets/js/29.f7a69544.js"><link rel="prefetch" href="/assets/js/30.e3062801.js"><link rel="prefetch" href="/assets/js/31.a510760d.js"><link rel="prefetch" href="/assets/js/32.7d281288.js"><link rel="prefetch" href="/assets/js/33.6ee8ebed.js"><link rel="prefetch" href="/assets/js/34.b32e8d79.js"><link rel="prefetch" href="/assets/js/35.59d10d28.js"><link rel="prefetch" href="/assets/js/36.e1bcc1a4.js"><link rel="prefetch" href="/assets/js/37.f6c202dd.js"><link rel="prefetch" href="/assets/js/38.f8d5161a.js"><link rel="prefetch" href="/assets/js/39.1b4b64a0.js"><link rel="prefetch" href="/assets/js/4.77ea1544.js"><link rel="prefetch" href="/assets/js/40.efb0ab3f.js"><link rel="prefetch" href="/assets/js/41.85c7d269.js"><link rel="prefetch" href="/assets/js/42.36b0df70.js"><link rel="prefetch" href="/assets/js/43.c3cc85ee.js"><link rel="prefetch" href="/assets/js/44.b1575b98.js"><link rel="prefetch" href="/assets/js/45.8de97fe3.js"><link rel="prefetch" href="/assets/js/46.1fe43d4f.js"><link rel="prefetch" href="/assets/js/47.70a2e6cc.js"><link rel="prefetch" href="/assets/js/48.bb81e90c.js"><link rel="prefetch" href="/assets/js/49.8f4841fa.js"><link rel="prefetch" href="/assets/js/5.b3344219.js"><link rel="prefetch" href="/assets/js/50.e7216bda.js"><link rel="prefetch" href="/assets/js/51.1a2faa73.js"><link rel="prefetch" href="/assets/js/52.f625df74.js"><link rel="prefetch" href="/assets/js/53.b0067c47.js"><link rel="prefetch" href="/assets/js/54.0c85623e.js"><link rel="prefetch" href="/assets/js/55.491eeca5.js"><link rel="prefetch" href="/assets/js/56.8c9ffe2c.js"><link rel="prefetch" href="/assets/js/57.51902d8c.js"><link rel="prefetch" href="/assets/js/58.6d40a504.js"><link rel="prefetch" href="/assets/js/59.dbb8914b.js"><link rel="prefetch" href="/assets/js/6.a7455cf0.js"><link rel="prefetch" href="/assets/js/60.99f5caf1.js"><link rel="prefetch" href="/assets/js/61.ad9ebd9b.js"><link rel="prefetch" href="/assets/js/62.8c2c2783.js"><link rel="prefetch" href="/assets/js/63.2334b133.js"><link rel="prefetch" href="/assets/js/64.c79651bc.js"><link rel="prefetch" href="/assets/js/65.791edb2c.js"><link rel="prefetch" href="/assets/js/66.bd09db30.js"><link rel="prefetch" href="/assets/js/67.1311433b.js"><link rel="prefetch" href="/assets/js/68.8be881a0.js"><link rel="prefetch" href="/assets/js/69.f9bb1936.js"><link rel="prefetch" href="/assets/js/7.274fc010.js"><link rel="prefetch" href="/assets/js/70.77e0e02e.js"><link rel="prefetch" href="/assets/js/71.da2cc493.js"><link rel="prefetch" href="/assets/js/72.f4a80206.js"><link rel="prefetch" href="/assets/js/73.8d4c37c8.js"><link rel="prefetch" href="/assets/js/74.7a7304d5.js"><link rel="prefetch" href="/assets/js/75.2e6d01bf.js"><link rel="prefetch" href="/assets/js/76.7de509a7.js"><link rel="prefetch" href="/assets/js/77.e5e58459.js"><link rel="prefetch" href="/assets/js/78.1590a03f.js"><link rel="prefetch" href="/assets/js/79.a96442ae.js"><link rel="prefetch" href="/assets/js/8.26184cc0.js"><link rel="prefetch" href="/assets/js/80.76d4faa5.js"><link rel="prefetch" href="/assets/js/81.c79d5483.js"><link rel="prefetch" href="/assets/js/82.47926428.js"><link rel="prefetch" href="/assets/js/83.ec12a53e.js"><link rel="prefetch" href="/assets/js/84.72120681.js"><link rel="prefetch" href="/assets/js/85.30643e8b.js"><link rel="prefetch" href="/assets/js/86.64375c3f.js"><link rel="prefetch" href="/assets/js/87.7a86109f.js"><link rel="prefetch" href="/assets/js/88.68858482.js"><link rel="prefetch" href="/assets/js/89.00d57e24.js"><link rel="prefetch" href="/assets/js/9.56db4e9b.js"><link rel="prefetch" href="/assets/js/90.b7f9de16.js"><link rel="prefetch" href="/assets/js/91.e9a8e6fb.js"><link rel="prefetch" href="/assets/js/92.0b986faf.js"><link rel="prefetch" href="/assets/js/93.7c26025a.js"><link rel="prefetch" href="/assets/js/94.c39f793d.js"><link rel="prefetch" href="/assets/js/95.b74865a0.js"><link rel="prefetch" href="/assets/js/96.62558dca.js"><link rel="prefetch" href="/assets/js/97.945f9035.js"><link rel="prefetch" href="/assets/js/98.be789959.js"><link rel="prefetch" href="/assets/js/99.1adf100e.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8c3033ea.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-cd01cc30><div data-v-cd01cc30><div id="loader-wrapper" class="loading-wrapper" data-v-4cd7a24a data-v-cd01cc30 data-v-cd01cc30><div class="loader-main" data-v-4cd7a24a><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-623c7d26 data-v-cd01cc30 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>自由·生活</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div class="hide" data-v-cd01cc30><header class="navbar" data-v-cd01cc30><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/avatar.jpg" alt="自由·生活" class="logo"> <span class="site-name">自由·生活</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-cd01cc30></div> <aside class="sidebar" data-v-cd01cc30><div class="personal-info-wrapper" data-v-2a0ed2ae data-v-cd01cc30><img src="/images/avatar.jpg" alt="author-avatar" class="personal-img" data-v-2a0ed2ae> <h3 class="name" data-v-2a0ed2ae>
    丶忆yu'man
  </h3> <div class="num" data-v-2a0ed2ae><div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>217</h3> <h6 data-v-2a0ed2ae>文章</h6></div> <div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>15</h3> <h6 data-v-2a0ed2ae>标签</h6></div></div> <hr data-v-2a0ed2ae></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/" aria-current="page" class="sidebar-link">码农生涯</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>码农生涯</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blogs/码农生涯/interview/java-interview-questions.html" class="sidebar-link">Java面试题</a></li><li><a href="/blogs/码农生涯/interview/算法.html" class="sidebar-link">算法</a></li><li><a href="/blogs/码农生涯/interview/Java基础.html" class="sidebar-link">Java基础</a></li><li><a href="/blogs/码农生涯/interview/计算机网络.html" class="sidebar-link">计算机网络</a></li><li><a href="/blogs/码农生涯/interview/数据库.html" class="active sidebar-link">数据库</a></li><li><a href="/blogs/码农生涯/interview/JVM虚拟机.html" class="sidebar-link">JVM虚拟机</a></li><li><a href="/blogs/码农生涯/interview/多线程.html" class="sidebar-link">多线程</a></li><li><a href="/blogs/码农生涯/interview/操作系统.html" class="sidebar-link">操作系统</a></li><li><a href="/blogs/码农生涯/interview/redis.html" class="sidebar-link">redis</a></li><li><a href="/blogs/码农生涯/interview/Spring.html" class="sidebar-link">Spring</a></li><li><a href="/blogs/码农生涯/interview/Linux.html" class="sidebar-link">Linux</a></li><li><a href="/blogs/码农生涯/interview/设计模式.html" class="sidebar-link">设计模式</a></li><li><a href="/blogs/码农生涯/interview/开放问题.html" class="sidebar-link">开放问题</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-623c7d26 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>数据库</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div data-v-cd01cc30><main class="page"><div class="page-title" style="display:none;"><h1 class="title">数据库</h1> <div data-v-8bc6ae5c><i class="iconfont reco-account" data-v-8bc6ae5c><span data-v-8bc6ae5c>丶忆yu'man</span></i> <i class="iconfont reco-date" data-v-8bc6ae5c><span data-v-8bc6ae5c>2021-03-31</span></i> <i class="iconfont reco-eye" data-v-8bc6ae5c><span id="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/interview/%E6%95%B0%E6%8D%AE%E5%BA%93.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-8bc6ae5c><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="iconfont reco-tag tags" data-v-8bc6ae5c><span class="tag-item" data-v-8bc6ae5c>面试</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><div class="custom-block tip"><p>Java好难，面试让我明白了</p></div> <h1 id="数据库">数据库</h1> <h3 id="三大范式">三大范式</h3> <h2 id="事务">事务</h2> <h3 id="简述事务">简述事务</h3> <p>事务是数据库进行操作的最小单位，事务有ACID四大特性。</p> <ol><li>介绍ACID四大特性</li> <li>四大隔离级别以及出现的问题</li> <li>事务背后的实现方式，也就是三大日志文件。</li></ol> <h3 id="acid">ACID</h3> <ul><li><p>原子性（Atomicity）</p> <p>事务被认为是不可分割的最小单元，事务中的操作要么全部执行成功，要么全部都不执行。</p></li> <li><p>一致性（Consistency）</p> <p>在一个事务前后数据库是从一个一致性状态到另一个一致性状态，一致性状态是指其它事务读的结果都是一样的。</p></li> <li><p>隔离性（Isolation）</p> <p>隔离性保证一个事务中的操作对其它事务是不可见的。</p></li> <li><p>持久性（Duration）</p> <p>事务提交后，那么对数据的修改那就是永久性的。</p></li></ul> <h3 id="事务怎样实现的">事务怎样实现的</h3> <p>事务的隔离性主要是通过锁机制来实现，锁又分为悲观锁和乐观锁，介绍数据库中各种锁，锁的实现方式。</p> <p>数据库中的所有功能其实都是为一致性而服务的，必须满足AID三大特性，才能做好一致性。</p> <ol><li><p>binlog</p> <p>binlog日志主要用来实现多个服务器之间的数据同步操作，也就是数据库的主从复制过程，binlog日志是在事务提交后才开始写入的，简述主从复制的过程</p></li> <li><p>undo log（撤销日志）</p> <p>事务的原子性主要通过undo log来进行实现，在一个事务中，每执行完一行更新sql语句，undo log中就会记录这条sql语句的反操作，例如执行一条加3的操作，undo log中就会记录一个减3的操作，当这个事务因为某种原因无法提交或者未能执行完毕时，就会通过undo log来撤销之前事务中已经执行的语句。</p></li> <li><p>redo log（回滚日志）</p> <p>事务的持久性主要通过redo log来进行实现，在一个事务中的所有操作都会记录到日志缓冲中，也就是log buffer，然后在事务提交时，先提交log buffer中的redo log缓冲同步到磁盘中redo log，也就是日志先行。然后再将事务操作后的数据文件同步到磁盘中，如果这时候系统出现问题，宕机，数据未持久化，那么在下次启动时就会通过redo log日志来恢复数据。</p></li></ol> <h3 id="隔离级别以及出现的问题">隔离级别以及出现的问题</h3> <ol><li><p>隔离级别</p> <ul><li>Read uncommited（未提交读）：任何情况都可能发生</li> <li>Read commited（提交读）：解决了脏读的问题</li> <li>Repeatable read（可重复读）：mysql的默认级别，解决了脏读和不可重复读的问题</li> <li>Serializable（序列化）：解决了脏读、不可重复读、幻读的问题</li></ul></li> <li><p>三大问题</p> <ul><li><p>脏读</p> <p>脏读是指在一个事务中读取到了另一个事务中未提交的更新数据。</p></li> <li><p>不可重复读</p> <p>在一个事务中读取到了另一个事务中已提交的更新数据。</p></li> <li><p>幻读</p> <p>在一个事务中读取到了另一个事务中已提交的新增数据。对于幻读，可以采用表锁的方式解决，在mysql中，采用MVCC和next-key lock的锁实现方式来解决。</p></li></ul></li></ol> <h3 id="mvcc">MVCC</h3> <h3 id="怎样解决快照读的幻读问题">怎样解决快照读的幻读问题</h3> <h2 id="索引">索引</h2> <h3 id="索引的实现方式">索引的实现方式</h3> <ol><li><p>B树</p> <ul><li><p>B树是每个结点不仅存储索引，还存储数据。</p></li> <li><p>B树本身是有序的，是一个平衡搜索树。</p></li> <li><p>B树的查询时间复杂度就是树的高度，也就是<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mo><mi>log</mi><mo>⁡</mo></mo><mi>m</mi></msub><mi>n</mi></mrow><annotation encoding="application/x-tex">\log_m{n}</annotation></semantics></math></span><span aria-hidden="true" class="katex-html"><span class="base"><span class="strut" style="height:0.93858em;vertical-align:-0.24414em;"></span><span class="mop"><span class="mop">lo<span style="margin-right:0.01389em;">g</span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.057252em;"><span style="top:-2.4558600000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">m</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.24414em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathnormal">n</span></span></span></span></span></p></li></ul></li> <li><p>B+树</p> <ul><li>B+树相对于B树而言，非叶子节点只存储索引值</li> <li>树中会出现重复值，也就是说结点中会包含父结点中某个值。</li> <li>所有的数据都存储在叶子结点上</li> <li>B+树中有两个头指针，一个指向树的根节点，另一个指向最左边的叶子结点，也就是最小值。</li></ul></li> <li><p>hash索引</p></li> <li><p>位图索引</p></li></ol> <h3 id="b树、b-树、红黑树、hash索引区别">B树、B+树、红黑树、hash索引区别</h3> <ol><li><p>B+树索引相对B树索引</p> <ul><li><p>空间利用率高，查询IO次数更少</p> <p>B+树相对于B树非叶子结点只存储索引，那么相对于每个结点也就能够存储更多的索引，在进行关键字比较的时候，一次能够比较更多的数据，减少IO查询次数。</p></li> <li><p>范围查询和全表查询更加方便</p> <p>B+树中有一个指向最左边叶子结点的指针，全表查询或者范围查询时直接从这个结点出发，以链表的形式进行遍历。</p> <p>而B树在进行范围查询时，需要进行中序遍历才能得到结果。</p></li> <li><p>查询也更加稳定</p> <p>B+树所有的数据都存放在叶子结点，那么每次查询都需要从根节点到叶子结点，查询非常稳定。</p></li></ul></li> <li><p>B+树相对于红黑树</p></li> <li><p>B+树索引相对于hash索引</p> <ul><li>Hash索引在等值查询时更加方便，直接通过计算键的hash值进行定位，获取数据。</li> <li>在范围查询时B+树更加有优势，因为Hash索引在建立索引后并不能保证原来数据的有序性，因此无法进行范围查询，而B+树数据都放在叶子结点，本身就是有序的。</li> <li>Hash索引无法应用联合索引的最左前缀原则，这个呐，主要是多索引的情况下，可以先对第一列索引查询，然后在得到的结果中去查第二列索引，查询数据会更少。</li> <li>B+树查询稳定，而Hash索引在针对很多冲突键值就会查询变慢。</li></ul></li> <li><p>B+树相对于红黑树</p> <ul><li><p>更少的IO查询次数</p> <p>红黑树本身是一个二叉树，而B+树可以是一个多叉树，由于查询的IO次数是由树的高度决定的，那么肯定B+树的高度会更小，因此IO查询次数也更少。</p></li> <li></li></ul></li></ol> <h3 id="索引类型">索引类型</h3> <p>索引类型主要分为单一索引，其中单一索引又可分为主键索引，唯一索引，也就是使用unique定义的字段，还有普通索引。</p> <p>另外还有联合索引，由多个列来进行索引排序，在这个情况下需要遵循最左前缀原则。</p> <h3 id="优缺点">优缺点</h3> <ol><li><p>索引的优点</p> <ul><li>建立索引后，数据库性能更高，查询更快</li> <li>索引能够唯一标识，保证每一行数据的唯一性</li> <li>加快表与表之间的连接，这里主要是先根据索引得到表中符合条件的结果，然后进行连接，速度更快</li> <li>在分组以及排序的时候，建立索引能够加快查询时间</li> <li>Innodb能够对索引查询进行优化</li></ul></li> <li><p>索引的缺点</p> <ul><li>首先建立索引需要耗费时间，尤其对于数据量非常大时，索引的建立时间较长。</li> <li>另外索引需要占用物理空间，另外一个表中有可能有多个索引，有聚集索引和非聚集索引，那么需要的空间开销比较大。</li> <li>索引不好维护，当数据进行更新或者删除后，索引也要进行动态维护，来保证索引的有序性，维护开销也比较大。</li></ul></li> <li><p>建立索引一定好吗</p> <p>建立索引不一定好，首先有些查询不使用索引查询会更快，mysql会自动不使用索引，因此建立索引只会浪费。</p> <p>另外当一个数据库数据量过少，或者查询操作过少，更多是更新和删除操作，那么建立索引也不会有优势。</p></li></ol> <h3 id="哪些列适合作索引、哪些不适合">哪些列适合作索引、哪些不适合</h3> <ol><li><p>适合作索引</p> <ul><li>定义为主键的列</li> <li>经常被查询的数据列</li> <li>表与表进行连接的外键列</li> <li>用作排序的数据列</li> <li>需要进行范围查询的数据列</li> <li>在where查询中经常进行条件判断的列</li></ul></li> <li><p>不适合作索引</p> <ul><li>很少进行查询的数据列</li> <li>取值很少的数据列，例如性别，只有男女两种取值，因此一般不创建索引</li> <li>数据很大的列，例如text、image等类型，数据量太大</li> <li>更新操作多于查询操作的数据列，查询相对太小，不需要建立索引。</li></ul></li></ol> <h3 id="sql语句调优">SQL语句调优</h3> <ul><li>索引优化
<ul><li>建立聚集索引来加快查询</li> <li>经常查询的数据建立索引，建立联合索引</li> <li>利用最左前缀原则减少查询的数据</li> <li>太长的数据列建立前缀索引</li> <li>不要建立无意义的索引</li></ul></li> <li>查询优化
<ul><li>使用Explain分析sql语句，查看sql查询是否使用索引，能够使用哪些索引，进行索引优化</li> <li>只查询自己需要的数据列，不使用select *查询</li> <li>建立合适的索引来减少查询的行数</li> <li>切分大查询，将大查询切分为多个小查询，保证一次查询不会锁住多个表或很多行记录，使其它的小查询不会被阻塞</li> <li>多表查询改为单表查询，主要是使缓存更高效，多表查询时如果一个表发生改变，那么整个多表查询的缓存就无法被重复使用，而进行多个单表查询的话，一个出现变化，其它表的查询缓存仍然能够被利用，并且也能够被其它查询使用。</li></ul></li></ul> <h3 id="为什么redis用跳表而mysql用b-树">为什么Redis用跳表而MySQL用B+树</h3> <h3 id="聚集索引和非聚集索引">聚集索引和非聚集索引</h3> <ul><li><p>聚集索引</p> <p>因为Innode存储引擎索引底层是采用B+树的数据结构，B+树的叶子存储的是key+data，如果data中直接存储是数据行，那么这就是一个聚集索引，聚集索引数据行的物理顺序与索引列的逻辑顺序是相同的，一个表中只能有一个聚集索引。聚集索引中的数据一般存储所有的数据列。</p></li> <li><p>非聚集索引</p> <p>唯一索引，普通索引，联合索引都是非聚集索引，在非聚集索引，data存储的是指向数据块的地址。非聚集索引只保证数据行逻辑上连续，而物理顺序并不一定连续，一个表中可存在多个聚集索引。</p> <p>当只查询索引列时，非聚集索引只需要查询一次，但是如果查询其它列的话，需要获取到主键后再去聚集索引中进行二次查询。一般可以采用建立联合索引来解决二次查询问题。</p></li></ul> <h3 id="索引失效的情况">索引失效的情况</h3> <ul><li>没有遵循最左前缀原则，也就是where查询条件中第一个不是前缀索引</li> <li>where条件中有or关键字查询</li> <li>where条件中有计算条件，也就是通过计算结果作为判断结果</li> <li>where条件中使用了函数</li> <li>like模糊查询使用了%作为开头</li> <li>where条件中比较要进行类型转换，这个其实就是使用了函数进行了转换</li> <li>mysql认为全表查询更快也不会使用索引</li></ul> <h2 id="锁">锁</h2> <h3 id="悲观锁和乐观锁">悲观锁和乐观锁</h3> <p>悲观锁和乐观锁是锁实现的两种策略</p> <ol><li><p>悲观锁</p> <p>悲观锁对于资源竞争采取的悲观策略，认为数据进行读写时一定会发生锁竞争，因此在对数据行进行读写时，都会对数据进行上锁，然后别的事务来操作这行数据时就会发生阻塞。</p></li> <li><p>乐观锁</p> <p>乐观锁对于资源竞争采取的乐观策略，认为一般情况下事务对数据的读取不会发生竞争，因此在读取数据时不会上锁，只有在数据更新时才会去检查数据是否被别的事务所修改，这里类似于CAS理论，一开始事务会查询该数据行，更新时再查询一次，发现不一致时就不进行数据行的修改。</p></li></ol> <h3 id="锁的类型">锁的类型</h3> <ol><li><p>读写锁</p> <ul><li><p>读锁</p> <p>读锁又被称为共享锁，也就是事务在查询数据时会对数据行上读锁，然后其它事务对该数据行的读操作不会阻塞</p></li> <li><p>写锁</p> <p>写锁又被称为互斥锁，事务在数据行进行更新修改会上写锁，其它事务对该数据行的任何操作都会阻塞</p></li></ul></li> <li><p>意向锁</p> <p>意向锁的提出主要是为了加快验证表中是否有数据行上锁的问题，在没有提出意向锁时，例如一个事务对表中某一行数据上了读锁，另一个事务需要对整个表上写锁，由于写锁与任何锁都会发生阻塞，因此需要去遍历整个表中所有的数据行，判断是否有行上锁，如果整个表数据行比较多，那就效率非常低了，因此采用了意向锁。</p> <p>意向锁规定在对上低粒度的锁时，必须对所有的高粒度上锁，也就是说在对表中某一行上了读锁或者写锁后，必须获取到整个表的意向读锁或者意向写锁，如果获取不到，那就发生阻塞。我们回到之前的问题，事务需要对整个表上写锁，由于之前的事务已经对整个表上了意向读锁，因此获取不到意向写锁，发生阻塞，而不用遍历去判断是否有数据行上锁。</p></li></ol> <h3 id="锁的三种实现方法">锁的三种实现方法</h3> <ul><li><p>行锁</p> <p>行锁就是对某一数据行进行上锁</p></li> <li><p>间隙锁</p> <p>间隙锁就是对一个范围进行上锁，但是不包括当前记录</p></li> <li><p>next-key lock</p> <p>行锁和间隙锁的结合体，对前后范围上锁，并且锁住当前记录，innodb默认情况下采用next-key lock</p> <p>当查询使用的是唯一键索引时，next-key lock就会退化成行锁，因为这时候单一索引的结构并不会发生并发问题，当我修改一个id = 5的数据时，其它的事务也可以插入id=6的数据。</p> <p>但是当查询使用的是索引时，也就是非聚集索引时，就必须使用next-key lock，例如我们有索引a和索引b，对b=xx的数据行上写锁，那在这种情况下必须先对聚集索引a==xxx的数据行上行锁，也是写锁，另外对非聚集索引b上间隙锁，来对前后范围进行上锁，保证其它事务在前后范围不能插入数据。</p></li></ul> <h3 id="数据库死锁、死锁怎样解决">数据库死锁、死锁怎样解决</h3> <h3 id="next-key-lock怎样解决当前读的幻读问题">next-key lock怎样解决当前读的幻读问题</h3> <h2 id="存储引擎">存储引擎</h2> <h3 id="简述存储引擎">简述存储引擎</h3> <h3 id="innodb和myism的区别">innodb和Myism的区别</h3> <h2 id="主从复制">主从复制</h2> <h3 id="简述主从复制">简述主从复制</h3> <h3 id="主从复制怎样实现">主从复制怎样实现</h3> <h2 id="备份">备份</h2> <h3 id="冷备份和热备份">冷备份和热备份</h3> <h3 id="两者优缺点">两者优缺点</h3> <h2 id="sql语句">SQL语句</h2> <h3 id="sql语句执行顺序">sql语句执行顺序</h3> <div class="language-mysql line-numbers-mode"><pre class="language-text"><code>select distinct t1.x, t2.xx 
from table1 t1 join table2 t2 on t1.xxx == t2.xxx
where t1.xx == &quot;xx&quot;
group by t1.x having avg(t1.x) &gt; 1
order by t1.xx desc
limit 10
执行顺序：
from -&gt; join -&gt; on -&gt; where -&gt; group by -&gt; avg -&gt; having -&gt; select -&gt; distinct -&gt; order by -&gt; limit
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h3 id="sql语句执行过程">sql语句执行过程</h3> <h3 id="ddl">DDL</h3> <h3 id="dml">DML</h3> <h3 id="索引-2">索引</h3> <h3 id="窗口函数">窗口函数</h3></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2021/5/22 下午7:12:29</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c8d125c6 data-v-c8d125c6><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c8d125c6><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c8d125c6></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c8d125c6></path></svg></div><APlayer audio="" fixed="true" mini="true" theme="#b7daff" loop="loop" order="random" preload="auto" volume="0.08" mutex="true" lrc-type="0" list-folded="true" list-max-height="250" storage-name="vuepress-plugin-meting" id="aplayer-fixed"></APlayer></div></div>
    <script src="/assets/js/app.0e76bb72.js" defer></script><script src="/assets/js/3.c5829877.js" defer></script><script src="/assets/js/1.695f3f80.js" defer></script><script src="/assets/js/238.8c792409.js" defer></script>
  </body>
</html>
